using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using Crusades.Helpers;

namespace Crusades.Geometry {
  public class PathBuilder : IDisposable {
    private Path path;
    private PathFigure currentFigure;



    public PathBuilder(Point start, Brush stroke, double strokeThickness) {
      path = new Path();
      var geometry = new PathGeometry();
      path.Data = geometry;
      currentFigure = new PathFigure();
      geometry.Figures.Add(currentFigure);
      currentFigure.StartPoint = start;

      path.StrokeThickness = strokeThickness;
      path.Stroke = stroke;

    }

    public Path AddLineSegment(Point B) {
      var lineSegment = new LineSegment { Point = B };
      currentFigure.Segments.Add(lineSegment);
      return path;
    }

    public Path AddBezierSegment(Vector[] controlPoints) {
      var segment = new BezierSegment {
        Point1 = controlPoints[1].toPoint(),
        Point2 = controlPoints[2].toPoint(),
        Point3 = controlPoints[3].toPoint()
      };
      currentFigure.Segments.Add(segment);
      return path;
    }

    public void Dispose() {
      path = null;
    }
  }
}